﻿using MediatR;
using System.CJL.API.Application.Command.RawMaterialCommand;
using System.CJL.Domain;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.RawMaterialCommandHanler
{
    /// <summary>
    /// 原料修改
    /// </summary>
    public class RawMaterialUpdateCommandHandler : IRequestHandler<RawMaterialUpdateCommand, int>
    {
        IRawMaterialRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        public RawMaterialUpdateCommandHandler(IRawMaterialRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 原料修改
        /// </summary>
        public async Task<int> Handle(RawMaterialUpdateCommand request, CancellationToken cancellationToken)
        {
			var RawMaterialDate = request.RawMaterialDate.Value.ToUniversalTime();

			return await _repository.UpdateAsync(new RawMaterial
            {
                RawMaterialId = request.RawMaterialId,
                RawMaterialNumbering = request.RawMaterialNumbering,
                RawMaterialName = request.RawMaterialName,
                RawMaterialClassify = request.RawMaterialClassify,
                RawMaterialSize = request.RawMaterialSize,
                RawMaterialSpecModel = request.RawMaterialSpecModel,
                RawMaterialAttribute = request.RawMaterialAttribute,
                RawMaterialUnit = request.RawMaterialUnit,
                RawMaterialinventory = request.RawMaterialinventory,
                RawMaterialType = request.RawMaterialType,
                RawMaterilStatus = request.RawMaterilStatus,
                RawMaterialNumber = request.RawMaterialNumber,
                RawMaterialDay = request.RawMaterialDay,
                InventoryMaximums = request.InventoryMaximums,
                InentoryLower = request.InentoryLower,
                RawMateriallocation = request.RawMateriallocation,
                RawMaterialDate = RawMaterialDate,
                RawMaterialReamrk = request.RawMaterialReamrk,
                RawMaterialImage = request.RawMaterialImage,
                IsDelete = request.IsDelete,
                AddTime = request.AddTime,
                AddName = request.AddName,
                UpdateName = request.UpdateName,
                UpdateTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
